package com.kai.kaiMybatis.sqlsession;

import java.lang.reflect.Proxy;

/**
 * @author kai
 * @version 1.0
 * @date 2024/7/31
 * @Description 搭建 Configuration（连接）和Executor 之间桥梁
 *              这里有操作DB的方法
 */
public class kaiSqlSession {
    //属性

    private Executor executor = new kaiExecutor();

    private kaiConfiguration kaiconfiguration = new kaiConfiguration();

    //编写方法，返回一条记录-对象
    public <T> T selectone(String sql, Object parameter) {
        return executor.query(sql, parameter);
    }

    //返回动态代理对象
    public <T> T getMapper(Class clazz) {

        return (T) Proxy.newProxyInstance(clazz.getClassLoader(),
                new Class[]{clazz}, new MapperProxy(this, kaiconfiguration, clazz));

    }



}
